﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

//TODO:REMOVE THIS ENTIRELY. Note made 2011-02-20.

namespace DGen
{
    /// <summary>
    /// Error/Bug handling. Not implemened properly.
    /// </summary>
    public partial class DBug
    {
        private DateTime dtime;

        private long memUsageA;
        private long memUsageB;
        private long memUsageDiff;
        private long TimeCounterDiff;

        private void markTime (int iCounter, long a, long b)
        {
            this.TimeCounterDiff = b - a;
            dtime = DateTime.Now;
            Console.WriteLine (this.TimeCounterDiff.ToString ());

            Debug.Write(iCounter + "\t\t" + dtime.TimeOfDay + "\tTICKS\t" + this.TimeCounterDiff);
            //+ dtime.Second.ToString() + "ss : " + dtime.Millisecond.ToString() + "ms");
            memUsageB = GC.GetTotalMemory(true);
            memUsageDiff = memUsageB - memUsageA;
            Debug.Write("\tBYTES\t" + memUsageB + "\t+" + memUsageDiff + " bytes");
            Debug.WriteLine(null);
            memUsageA = memUsageB;
        }

        private void markTime(int iCounter)
        {
            dtime = DateTime.Now;
            Debug.Write(iCounter + "\t\t" + dtime.TimeOfDay + "\tTICK_NUMBER\t" + dtime.Ticks);
            //+ dtime.Second.ToString() + "ss : " + dtime.Millisecond.ToString() + "ms");
            memUsageB = GC.GetTotalMemory(true);
            memUsageDiff = memUsageB - memUsageA;
            string operatorStr = "";
            if (memUsageDiff < 0)
            {
                operatorStr = "-\t";
            }
            else
                operatorStr = "+\t";
            Debug.Write("\tBYTES\t" + memUsageB + "\t" + operatorStr + memUsageDiff + "\tbytes");
            Debug.WriteLine(null);
            memUsageA = memUsageB;
        }

        private string getTime()
        {
            dtime = DateTime.Now;
            return (dtime.TimeOfDay + " : " + dtime.Second + "ss : " + dtime.Millisecond + "ms");
        }


        //public static void markTime()
        //{
        //    long CurrentMem = GC.GetTotalMemory(true);
        //    DateTime CurrentTime = DateTime.Now;


        //    Debug.Write(CurrentTime.TimeOfDay.ToString());
        //    Debug.Write("\tBYTES\t" + String.Format("{0:N}", CurrentMem));
        //    Debug.WriteLine(null);
        //}

        /// <summary>
        /// Returns the amount of memory in use (sort of) and the time in a formatted string.
        /// </summary>
        /// <returns></returns>
        public static string getMemTime()
        {
       
            long CurrentMem = GC.GetTotalMemory(false);
             Process p = Process.GetCurrentProcess();
             long xBytes = p.WorkingSet64;
            DateTime CurrentTime = DateTime.Now;
            string endTxt = Environment.NewLine;
            endTxt += String.Format("{0:N}", xBytes) + " Bytes" + Environment.NewLine;
            endTxt += String.Format("{0:N}", CurrentMem) + " Bytes" + Environment.NewLine;
            endTxt += CurrentTime.ToLongTimeString();
            return endTxt;
        }
    }
}
